<?php

namespace app\admin\service;

use app\admin\model\ActionLog;
use app\common\service\BaseService;
use app\http\exception\AuthException;

class ActionLogService extends BaseService {

    public function getActionLogList($extendQueryHelper, $data) {

        $query = ActionLog::build()
                          ->where($extendQueryHelper->where)
                          ->order($extendQueryHelper->sort, $extendQueryHelper->order);
        return $extendQueryHelper->is_page ? $query->_paginate() : $query->select();
    }

    public function getActionLogItem($id) {
        return ActionLog::build()
                        ->findOrFail($id);
    }

    public function delActionLogItem($ids) {
        return ActionLog::build()
                        ->whereIn('action_log_id', $ids)
                        ->delete();
    }

    public function setActionLogItem($data, $id) {
        $info = ActionLog::build()
                         ->findOrFail($id);
        if (!$info) {
            throw new AuthException('数据不存在');
        }

        return $info->save($data);
    }


    public function addActionLogItem($data) {
        $model = new ActionLog();
        return $model->save($data);
    }

    public function clearActionLog() : bool
    {
        return ActionLog::build()->where("1=1")->delete();
    }


}
